package com.zryc.shop.sms.controller;

import com.zryc.shop.base.Result;
import com.zryc.shop.sms.entity.HomeBrand;
import com.zryc.shop.sms.entity.HomeRecommendProduct;
import com.zryc.shop.sms.service.IHomeRecommendProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 人气推荐商品表 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@Api("热门商品推荐")
@RequestMapping("/sms/home/recommendProduct")
public class HomeRecommendProductController {

    @Autowired
    private IHomeRecommendProductService homeRecommendProductService;

    @GetMapping("/list")
    @ApiOperation("分页查询")
    public Result list(@RequestParam(required = false) @ApiParam(value = "品牌名称关键词") String productName,
                       @RequestParam(required = false) @ApiParam(value = "推荐状态") Integer recommendStatus,
                       @RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                       @RequestParam(defaultValue = "5") @ApiParam(value = "每页显示条数", required = true) Integer pageSize){
        return Result.ok(homeRecommendProductService.list(productName,recommendStatus,pageNum,pageSize));
    }

    @PostMapping("/create")
    @ApiOperation("选择推荐品牌")
    public Result create(@RequestBody List<HomeRecommendProduct> homeRecommendProductList){
        return Result.ok(homeRecommendProductService.saveBatch(homeRecommendProductList));
    }

    @PostMapping("/update/recommendStatus")
    @ApiOperation("设置推荐/取消")
    public Result updateRecommendStatus(String ids, Integer recommendStatus){
        return Result.ok(homeRecommendProductService.updateRecommendStatus(ids,recommendStatus));
    }
    @PostMapping("/delete")
    @ApiOperation("删除品牌推荐")
    public Result delete(String ids){
        String[] idList=ids.split(",");
        return Result.ok(homeRecommendProductService.removeBatchByIds(Arrays.asList(idList)));
    }

    @PostMapping("/update/sort/{id}")
    @ApiOperation("设置推荐排序值")
    public Result updateSort(@PathVariable Long id, @RequestParam Integer sort){
        return Result.ok(homeRecommendProductService.updateSort(id,sort));
    }




}
